//
//  MSTaBbarController.m
//  觅尚
//
//  Created by No.8 on 2019/3/19.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSTaBbarController.h"
#import "MSNavigationController.h"
#import "MSHomeController.h"
#import "MSMationController.h"
#import "MSMeController.h"
#import "MSServiceTerminalHomeController.h"
#import "MSFinanceController.h"
#import "MSSeeAttendanceStatisticsController.h"
#import "MSAccuntLoginController.h"
#import "MSRoomManagementController.h"
#import "MSSweepCodeActivityController.h"
#import "MSDepartmentAttendanceController.h"
#import "MSKitchenController.h"
#import "MSKaoqingController.h"
#import "MSAcctunModel.h"
#import "MSQiantaiRoomMentController.h"

@interface MSTaBbarController ()
@end

@implementation MSTaBbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"array"];
    NSMutableArray * ListArray = [MSAcctunModel mj_objectArrayWithKeyValuesArray:arr];
    NSLog(@"ListArray%@",arr);
    [UINavigationBar appearance];
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, self.tabBar.height)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:backView atIndex:0];
    self.tabBar.opaque = YES;
    self.tabBar.translucent = NO;
    
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    attrs[NSForegroundColorAttributeName] = WYCRGBColor(220, 221, 228);
    
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    selectedAttrs[NSForegroundColorAttributeName] = WYCRGBColor(195, 70, 117);
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
    
    
    
    
    for(MSAcctunModel *  model in ListArray){
        int key = [model.bme_tag intValue];
        
//        WYCLog(@"=-======%d",key);
    switch (key) {
        case 0:
            //总经理首页控制器
            [self setupChildVc:[[MSHomeController alloc] init] title:@"首页" image:@"Home_nomor_icon" selectedImage:@"Home_select_icon"];
            break;
        case 1:
            //活动资讯
            [self setupChildVc:[[MSMationController alloc] init] title:@"活动资讯" image:@"Mation_nomor_icon" selectedImage:@"Mation_select_icon"];
            break;
        case 2:
            //个人中心
            [self setupChildVc:[[MSMeController alloc] init] title:@"我的" image:@"Me_select_icon" selectedImage:@"Me_nomor_icon"];
            break;
        case 3:
            //考勤
            [self setupChildVc:[[MSServiceTerminalHomeController alloc] init] title:@"打卡" image:@"Home_nomor_icon" selectedImage:@"Home_select_icon"];
            break;
        case 4:
            //考勤统计
            [self setupChildVc:[[MSKaoqingController alloc] init] title:@"考勤统计" image:@"Home_kqtjNomer_icon" selectedImage:@"Home_kqtjSelact_icon"];
            break;
        case 5:
            //财务端
            [self setupChildVc:[[MSFinanceController alloc] init] title:@"首页" image:@"Home_nomor_icon" selectedImage:@"Home_select_icon"];
            break;
        case 6:
            //普通员工
            [self setupChildVc:[[MSQiantaiRoomMentController alloc] init] title:@"首页" image:@"Home_nomor_icon" selectedImage:@"Home_select_icon"];
            break;
        
        default:
            //        厨品
            [self setupChildVc:[[MSKitchenController alloc] init] title:@"厨品" image:@"Home_nomor_icon" selectedImage:@"Home_select_icon"];
            break;
    }
    }
    
    
//
    
    
    
    
    //财务端
//    [self setupChildVc:[[MSSeeAttendanceStatisticsController alloc] init] title:@"考勤统计" image:@"Home_kqtjNomer_icon" selectedImage:@"Home_kqtjSelact_icon"];
    
////
//
//
    
    
    
}
/** 数组*/
- (NSMutableArray *)ListArray {
    if (!_ListArray) {
        _ListArray = [NSMutableArray new];
    }
    return _ListArray;
}
/**
 * 初始化子控制器
 */
- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置文字和图片
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    
    // 包装一个导航控制器, 添加导航控制器为tabbarcontroller的子控制器
    MSNavigationController *nav = [[MSNavigationController alloc] initWithRootViewController:vc];
    nav.navigationBar.barTintColor = [UIColor whiteColor];
    
    [self addChildViewController:nav];
}

@end
